package models

import "strconv"

type User struct {
	ID
	Username   string `json:"username" gorm:"type:string;size:50;uniqueIndex;comment:用户名"`
	Password   string `json:"-" gorm:"type:string;size:60;comment:密码"`
	Headshot   string `json:"headshot" gorm:"type:string;size:100;comment:头像"`
	Email      string `json:"email" gorm:"type:string;size:100;uniqueIndex;comment:邮箱"`
	Phone      string `json:"phone" gorm:"type:string;size:15;uniqueIndex;comment:手机号"`
	Province   string `json:"province" gorm:"type:string;size:50;comment:省"`
	City       string `json:"city" gorm:"type:string;size:50;comment:市"`
	Area       string `json:"area" gorm:"type:string;size:50;comment:区"`
	ClientId   string `json:"client_id" gorm:"type:string;size:30;comment:设备id"`
	ClientPort string `json:"client_port" gorm:"type:string;size:10;comment:设备端口"`
	LoginTime  uint64 `json:"login_time" gorm:"comment:最近登录时间（毫秒时间戳）"`
	LogoutTime uint64 `json:"logout_time" gorm:"comment:最近登出时间（毫秒时间戳）"`
	Status     string `json:"status" gorm:"type:string;size:1;default:1;comment:状态 0不可用 1可用 2登录中 3登出"`
	Timestamps        // 嵌入修正后的 Timestamps 结构体
}

func (u User) TableName() string {
	return "sys_user"
}

// GetUid 实现JWT的接口方法
func (u User) GetUid() string {
	return strconv.Itoa(int(u.ID.ID))
}
